import 'package:flutter/material.dart';

/// An [TextFormField] with a label on its left.
class HorizontalLabelTextFormField extends StatelessWidget {
  const HorizontalLabelTextFormField({
    super.key,
    required this.label,
    this.textAlign = TextAlign.left,
    this.hintText,
    this.validator,
    this.onSaved,
  });

  final String label;
  final TextAlign textAlign;
  final String? hintText;
  final FormFieldValidator<String?>? validator;
  final FormFieldSetter<String?>? onSaved;

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        Text(label),
        const SizedBox(width: 10.0),
        Expanded(
          child: TextFormField(
            keyboardType: TextInputType.text,
            textAlign: textAlign,
            decoration: InputDecoration(
              hintText: hintText,
              hintStyle: Theme.of(context).textTheme.bodySmall,
              border: InputBorder.none,
            ),
            validator: validator,
            onSaved: onSaved,
          ),
        ),
      ],
    );
  }
}
